package JDBC;


import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.util.DruidWebUtils;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

//德鲁伊硬编码实现
public class druid {

    public void testHard() throws SQLException {

        DruidDataSource dataSource=new DruidDataSource();

        //直接使用代码设置连接池连接方式
     dataSource.setUrl("jdbc:mysql://localhost:3306/student");
     dataSource.setUsername("root");
     dataSource.setPassword("080666");
     dataSource.setDriverClassName("com.mysql.jdbc.Driver");

     dataSource.setInitialSize(5);
     dataSource.setMaxActive(10);

     Connection connection = dataSource.getConnection();

     connection.close();


    }
    @Test //软连接
    public void test() throws Exception {
        Properties properties=new Properties();
        InputStream ips = druid.class.getClassLoader().getResourceAsStream("druid.properties}");
        properties.load(ips);

        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        Connection connection = dataSource.getConnection();


        connection.close();
    }
}
